<html>
<head>
    <#assign basePath=request.contextPath>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>后台管理系统</title>
    <!-- Bootstrap Core CSS -->
    <link href="${basePath}/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .input-group{ position: relative;}
        .input-group #rlname{ width: 300px;}
        .input-group small{ position: absolute; top: 5px; left: 390px; z-index: 200;}
    </style>
</head>
<body>
<div id="page-wrapper" style="padding: 0 15px;">
    <div class="row">
        <div class="col-lg-12">
            <br>
            <div class="panel panel-default">
                <div class="panel-body">
                    <form role="myForm" id="myForm">
                        <input type="hidden" name="id" id="id" value="${role.id?c}">
                        <div class="form-group input-group">
                            <span class="input-group-addon">角色名称</span>
                            <input type="text" class="form-control" name="rlname" id="rlname" size="100" value="${role.rlname!}" maxlength="20">
                        </div>
                        <div class="form-group input-group">
                            <span class="input-group-addon">角色描述</span>
                            <input type="text" class="form-control" name="memo" id="memo" value="${role.memo!}" maxlength="100">
                        </div>
                        <div class="form-group input-group">
                            <label>&nbsp;角色状态&nbsp;&nbsp;&nbsp;</label>
                            <input type="radio" name="status" value="0"  checked> 停用
                            <input type="radio" name="status" value="1" > 启用（仅限本企业数据）
                            <input type="radio" name="status" value="2" > 启用（本企业数据以及旗下公司所有数据）
                        </div>
                        <hr>
                        <div class="row" align="center">
                            <div class="col-xs-12">
                                <button type="button" class="btn btn-primary" onclick="submitForm();">确定</button>
                                <button type="button" class="btn btn-primary" onclick="closePage();">关闭</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="${basePath}/bootstrap/js/jquery.min.js" type="text/javascript"></script>
<script src="${basePath}/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<!-- layer JavaScript -->
<script src="${basePath}/bootstrap/plugin/layer/layer.js" type="text/javascript"></script>
<script type="text/javascript" src="https://cdn.bootcss.com/bootstrap-validator/0.5.3/js/bootstrapValidator.min.js"></script>
<script type="text/javascript">
    $(window).bootstrapValidator || document.write('<script src="${basePath}/bootstrap/js/bootstrapValidator.min.js"><\/script>');
</script>
<script>
    var action="${action!}";
    $(function () {
        var statusTmp = '${role.status!}';
        if (statusTmp == '0') {
            $("input[name=status]:eq(0)").attr("checked",'checked');
        } else if (statusTmp == '1') {
            $("input[name=status]:eq(1)").attr("checked",'checked');
        } else if (statusTmp == '2') {
            $("input[name=status]:eq(2)").attr("checked",'checked');
        }
    });

    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    //关闭窗口并刷新页面
    function closePage() {
        parent.layer.close(index);
    }
    function submitForm() {

        var bsVal = $("#myForm").data('bootstrapValidator');
        bsVal.validate();
        if(bsVal.isValid()) {

            $.ajax({
                type: 'POST',
                url: '${basePath}/admin/role/' + action,
                data: {
                    id: $('#id').val(),
                    rlname: $('#rlname').val(),
                    memo: $('#memo').val(),
                    status: $("input[type='radio']:checked").val()
                },
                dataType: 'json',
                beforeSend: function () {
                    // TODO FORM ...
                },
                success: function (data) {
                    if (data.code == '0' || data.code == '0000') {
                        layer.alert('操作成功！', {
                            icon: 6
                        });
                        parent.search(parseInt(parent.$('.active').attr('jp-data')));
                        setTimeout("closePage()", 2000);
                        //closePage();
                    } else {
                        layer.alert(data.desc, {
                            icon: 56
                        });
                    }
                },
                error: function () {
                    layer.alert('系统错误', {
                        icon: 5
                    });
                }
            });
        }
    }
    $('#myForm').bootstrapValidator({
        fields: {
            rlname: {
                validators: {
                    notEmpty: {
                        message: '请输入角色名称'
                    }
                }
            }
        }
    })
</script>
</body>
</html>
